import java.util.ArrayList;
import java.util.List;
import java.util.Random;
//ArrayList 底层其实就是一个动态的数组【顺序表】
/**
 *  买牌
 *  洗牌
 *  揭牌
 */
public class Pokers {
    public static final String[] SUITS ={"♥","♠","♣","♦"};

    //买牌
    public static List<Poker> buyPokers(){
        List<Poker> pokerList = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 13; j++) {
                String suit = SUITS[i];
                pokerList.add( new Poker(suit,j));
            }
        }
        return pokerList;
    }
    public static void swap(List<Poker> pokerList,int i,int index){
        Poker tmp = pokerList.get(i);
        pokerList.set(i,pokerList.get(index));
        pokerList.set(index,tmp);
    }
    //洗牌
    public static void shuffle(List<Poker> pokerList){
        Random random = new Random();
        for (int i = pokerList.size()-1; i >0 ; i--) {
            int index = random.nextInt(i);
            swap(pokerList,i,index);
        }
    }

    public static void main(String[] args) {
        List<Poker> pokerList = buyPokers();
        System.out.println("买牌："+pokerList);
        shuffle(pokerList);
        System.out.println("洗牌："+pokerList);
        //揭牌
        List<Poker> hand1 = new ArrayList<>();
        List<Poker> hand2 = new ArrayList<>();
        List<Poker> hand3 = new ArrayList<>();
        List<List<Poker>> pokerTmp = new ArrayList<>();
        pokerTmp.add(hand1);
        pokerTmp.add(hand2);
        pokerTmp.add(hand3);
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                /*Poker poker1 = pokerList.remove(0);
                List<Poker> hand = pokerTmp.get(j);
                hand.add(poker1);*/
                pokerTmp.get(j).add(pokerList.remove(0));
            }
        }
        for (int i = 1; i <= pokerTmp.size(); i++) {
            System.out.println("第"+i+"个人揭的牌"+pokerTmp.get(i-1));
        }
        System.out.println("剩下的牌："+pokerList);
    }
}
